import java.util.ArrayList;
import java.util.List;

public class Seven {

	public static void main(String[] args) {
		
		SinglyLinkedListJosephus(5,0,2);
//		DoublyLinkedListJosephus(5,0,2);

	}
	 public static void SinglyLinkedListJosephus(int number,int start,int distance){ 
		 
		    String[] list = new String[5];
			for(int i=0;i<list.length;i++) {
				list[i]=((char)('A'+i)+"");
			}

			 SinglyLinkedList<String> a=new SinglyLinkedList<String>(list); 
	        System.out.println("约瑟夫环("+number+","+start+","+distance+"),");  
	        a.showList(); 
	        int i=start;  
	        while(a.size>1){  
	            i=(i+distance-1)%a.size;  
	            a.remove(i);
	        }  
	        System.out.println();
	        System.out.print("被赦免的罪犯是：");
	        a.showList();
	    } 
	 
	 public static void DoublyLinkedListJosephus(int number,int start,int distance){ 
		 
		    String[] list = new String[5];
			for(int i=0;i<list.length;i++) {
				list[i]=((char)('A'+i)+"");
			}

			DoublyLinkedList<String> a=new DoublyLinkedList<String>(list); 
	        System.out.println("约瑟夫环("+number+","+start+","+distance+"),");  
	        a.showList(); 
	        int i=start;  
	        while(a.size>1){  
	            i=(i+distance-1)%a.size;  
	            a.remove(i);
	        }  
	        System.out.println();
	        System.out.print("被赦免的罪犯是：");
	        a.showList();
	    }  

}
